package cn.topcodes.tcsf.admin.commons.api;

import org.springframework.context.annotation.Bean;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@EnableSwagger2
public class SwaggerConfig {

    private String regexUrl;

    public String getRegexUrl() {
        return regexUrl;
    }

    public void setRegexUrl(String regexUrl) {
        this.regexUrl = regexUrl;
    }

    ApiInfo apiInfo() {
        return new ApiInfoBuilder()
            .title("Rest API Document")
            .description("TCSF Admin Framework Web API")
            .license("")
            .licenseUrl("http://www.topcodes.cn")
            .termsOfServiceUrl("")
            .version("1.0.0")
            .contact(new Contact("","", ""))
            .build();
    }

    @Bean
    public Docket customImplementation(){
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .paths(PathSelectors.regex(regexUrl))
                    .build()
//                .directModelSubstitute(org.joda.time.LocalDate.class, java.sql.Date.class)
//                .directModelSubstitute(org.joda.time.DateTime.class, java.util.Date.class)
                .apiInfo(apiInfo());
    }

}
